let count_down_timer = '';

/**
 * 倒计时
 *
 * @param {Number} end_time （倒计时结束的时间戳） 一般都是10位
 */
function countDown(end_time) {
    let nowTime = new Date().getTime();
    let endTime = new Date(end_time * 1000).getTime();
    let obj = null;

    if (endTime - nowTime > 0) {
        let time = (endTime - nowTime) / 1000;
        // 获取天，时，分，秒
        let day = parseInt(time / (60 * 60 * 24));
        let hour = parseInt(time % (60 * 60 * 24) / 3600);
        let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
        let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);

        // console.log(time, day, hour, min, sec);

        obj = {
            day: this.timeFormat(day),
            hour: this.timeFormat(hour),
            min: this.timeFormat(min),
            sec: this.timeFormat(sec),
        }

        count_down_timer = setTimeout(() => {
            this.countDown();
        }, 1000);

        return obj;
    } else {
        obj = {
            day: '00',
            hour: '00',
            min: '00',
            sec: '00',
        };
        return obj;
    }
}
// 时间格式化，不足两位的在前面补零
function timeFormat(time) {
    return time < 10 ? '0' + time : time;
}

countDown(1546272000);